package com.tencent.sr.iris.basic.saas.service.convert;

import com.tencent.sr.iris.activity.interfaces.enums.IsParticipatedEnum;
import com.tencent.sr.iris.activity.interfaces.request.IrisPaginationRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.BatchDataRequest;
import com.tencent.sr.iris.activity.interfaces.response.activity.BatchDataResponse;
import com.tencent.sr.iris.basic.saas.common.enums.TaskEstimateStatusEnum;
import com.tencent.sr.iris.basic.saas.common.enums.UserTaskStatusEnum;
import com.tencent.sr.iris.basic.saas.interfaces.request.activity.ActivityTaskPageRequest;
import com.tencent.sr.iris.basic.saas.interfaces.response.activity.ActivityTaskPageResponse;
import com.tencent.sr.iris.basic.saas.interfaces.response.activity.SentAwardInfo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Date;
import java.util.Objects;
import java.util.Optional;

@Mapper(componentModel = "spring", imports = {Date.class, Objects.class, Optional.class,
        UserTaskStatusEnum.class, TaskEstimateStatusEnum.class, IsParticipatedEnum.class})
public interface ActivityTaskConvert {

    IrisPaginationRequest<BatchDataRequest> buildBatchDataRequest(IrisPaginationRequest<ActivityTaskPageRequest> request);

    BatchDataRequest buildBatchDataRequest(ActivityTaskPageRequest request);


    @Mapping(target = "traineeTime", expression = "java(handleTime(response.getTraineeTime()))")
    @Mapping(target = "awardSendTime", expression = "java(handleTime(response.getAwardSendTime()))")
    @Mapping(target = "specialInviteTime", expression = "java(handleTime(response.getSpecialInviteTime()))")
    @Mapping(target = "superiorSpecialInviteTime", expression = "java(handleTime(response.getSuperiorSpecialInviteTime()))")
    ActivityTaskPageResponse buildActivityTaskPageResponse(BatchDataResponse response);

    default Long handleTime(Long time) {
        if (time == null || time <= 0) {
            return null;
        }
        return time;
    }

    @Mapping(target = "stage", expression = "java(Optional.ofNullable(response.getTier()).orElse(0))")
    @Mapping(target = "awardSendTime", expression = "java(handleTime(response.getAwardSendTime()))")
    @Mapping(target = "awardAmount", source = "sendAward")
    SentAwardInfo buildAwardInfoFromBatchDataResponse(BatchDataResponse response);

}